package com.tour.service.impl;

import com.tour.bean.ScenicSpot;
import com.tour.dao.ScenicSpotMapper;
import com.tour.service.ScenicSpotService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ScenicSpotServiceImpl
 * @Author 张梦兴
 * @Date 2020/3/9 21:46
 * @describe
 */
@Service
public class ScenicSpotServiceImpl implements ScenicSpotService {

    private final Logger log=Logger.getLogger(ScenicSpotServiceImpl.class);

    @Autowired
    private ScenicSpotMapper dao;

    @Override
    public int insert(ScenicSpot scenicSpot) {

        // valid
        if (scenicSpot == null) {
            //return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        int result=dao.insert(scenicSpot);
        return result;
    }


    @Override
    public int delete(int id) {
        int ret = dao.delete(id);
        return ret;
    }


    @Override
    public int update(ScenicSpot scenicSpot) {
        int ret = dao.update(scenicSpot);
        return ret;
    }


    @Override
    public ScenicSpot load(int id) {
        return dao.load(id);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize,String title,String star) {
        Map<String,Object> param=new HashMap<>();
        param.put("offset",offset);
        param.put("pageSize",pagesize);
        param.put("title",title);
        param.put("star",star);

        List<ScenicSpot> pageList = dao.pageList(param);
        int totalCount = dao.pageListCount(param);

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

}
